const crypto = require('crypto')
// aes加密算法
function encrypt(key,iv,data) {
  let dep =crypto.createCipheriv("aes-128-cbc",key,iv)

  return dep.update(data,'binary','hex') + dep.final('hex')
}

function decrypt(key,iv,crypted) {
  crypted = Buffer.from(crypted,'hex').toString('binary')

  let dep = crypto.createDecipheriv('aes-128-cbc',key,iv)
  return dep.update(crypted,'binary','utf8')+dep.final('utf8')
}

// 16*8 = 128
let key = 'abcdef1234567890'
let iv = 'atydef1234567890'
let data = 'zy'
let cryted = encrypt(key,iv,data)

console.log(cryted)


let decrypted = decrypt(key,iv,cryted)
console.log(decrypted)

